package com.dayuanit.dy15.lesson20.demo3;

import java.util.Objects;

public class Dog {
    private String name;
    private int price;

    public Dog() {}

    public Dog(String name, int price) {
        this.name = name;
        this.price = price;
    }

//    @Override
//    public String toString() {
//        return "name=" + this.name + " price=" + this.price;
//    }


    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

    /**
     * 当要重写equals方法的时候，也要重写hashCode方法
     * @return
     */
    @Override
    public int hashCode() {
        return Objects.hash(this.name, this.price);
    }

    /**
     * 怎么样比较 完全取决于你的业务
     * @param obj
     * @return
     */
    @Override
    public boolean equals(Object obj) {
        if (null == obj) {
            return false;
        }

        if (this == obj) {
            return true;
        }

        if (obj instanceof Dog) {
            Dog otherDog = (Dog)obj;
            return this.name.equals(otherDog.name) && this.price == otherDog.price;
        }

        return false;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }
}
